<template>
	<view class="login">
		<image class="image-text" :src="resourceUrl+'login-top-text.png'" alt="" />
		<view class="ipt-wrap">
			<view class="user">
				<image :src="resourceUrl+'login-user.png'" class="user-icon" mode=""></image>
				<input class="ipt" v-model="login.mobile" placeholder-class="ph-color" placeholder="手机号" />
			</view>
			<view class="pwd">
				<image :src="resourceUrl+'login-psd.png'" class="psd-icon" mode=""></image>
				<input :password="psdFlag" class="ipt" placeholder-class="ph-color" placeholder="密码"
					v-model="login.password" />
				<image class="eye" v-if="psdFlag" @click="psdFlag=false" :src="resourceUrl+'eye-close.png'" mode="">
				</image>
				<image class="eye" v-else @click="psdFlag=true" :src="resourceUrl+'login-eye.png'" mode=""></image>
			</view>
			<button class="forget-psd" @click="forgetPsd">忘记密码？</button>
			<button class="login-enter" @click="loginEnter">登录</button>
			<image :src="resourceUrl+'login-huanbao-bgc.png'" class="huanbao" mode=""></image>
			<text class="text">郑州市生态环境局新郑综合行政执法大队</text>
		</view>
		<view class="mask" v-if="maskFlag == true">
			<view class="wrap">
				<view class="title">选择企业</view>
				<view class="selection">
					<uni-data-select v-model="login.enterprisename" :localdata="enterpriseList"
						@change="enterpriseChange"></uni-data-select>
				</view>
				<button @click="againLogin">确认</button>
			</view>
			<image @click="maskFlag=false" :src="resourceUrl+'black-err.png'" mode=""></image>
		</view>
	</view>
</template>
<script setup>
	import {
		resourceUrl,

	} from '../../request/config.js'
	import TitleName from '../../components/titleName.vue'
	import http from '../../request/index.js'
	import {
		ref
	} from 'vue'
	import {
		onShow,
	} from "@dcloudio/uni-app"
	let enterpriseList = ref([])
	let enterpriseChange = (e) => {
		console.log(e, 'enterprise');
	}
	let login = ref({
		mobile: '',
		password: ''
	})

	// 管理员账号
	// C/2005 徐晶 部门管理员
	// 15093387000/ 7000 范晓  光大管理员
	// 13525524123/4123 王锴锋
	// 15188336333/6333 赵静 白象管理员
	// 18600136076/6076 白象（新郑）有限公司
	// 15838222109/2109  赵绘利  管理员
	let psdFlag = ref(true)
	let maskFlag = ref(false)
	onShow(() => {
		login.value.mobile = uni.getStorageSync('mobile')
		login.value.password = uni.getStorageSync('password')
	})
	let forgetPsd = () => {
		uni.navigateTo({
			url: "/pages/forgetpwd/index"
		})
	}
	let againLogin = () => {
		loginEnter()
	}
	let loginEnter = () => {
       console.log("xha");
		uni.showLoading({
			title: "登录中......",
			icon: "none"
		})
		http({
			url: "/loginv2",
			method: "post",
			data: {
				...login.value,

			}
		}).then((res) => {
			if (res.code == 0) {
				uni.hideLoading()

				if (res.data.isMany == 1) {
					maskFlag.value = true
					enterpriseList.value = res.data.lstEnterpriseMany.map((item) => {
						return {
							value: item.customername,
							text: item.customername
						}
					})
					login.value.enterprisename = enterpriseList.value[0].value
				} else {
					// userno 1 法人 2 负责人
					uni.setStorageSync("TOKEN", res.data.token)
					uni.setStorageSync('mobile', login.value.mobile)
					uni.setStorageSync('password', login.value.password)
					uni.setStorageSync('usertype', res.data.usertype)
					uni.setStorageSync('uid', res.data.uid)
					uni.setStorageSync('userno', res.data.userno)
					uni.setStorageSync('parentdepartmentname', res.data.parentdepartmentname)
					uni.setStorageSync('departmentname', res.data.departmentname)
					uni.setStorageSync('username', res.data.username)
					uni.hideToast();
					uni.setStorageSync('boban', JSON.stringify(res.data.mobanid.split(',')))
					wx.requestSubscribeMessage({
						tmplIds: res.data.mobanid.split(','),
						success(res) {
							uni.login({
								provider: 'weixin', //使用微信登录
								success: function(loginRes) {
									http({
										url: "/openid/getOpenId",
										data: {
											code: loginRes.code
										}
									}).then((res) => {})
								}
							});
						},
						fail(err) {
							console.log("授权失败", err);
						},
					});
					if (res.data.isNeedEnterpriseInfo) {
						uni.navigateTo({
							url: "/homePageOther/edit-enterprise-msg/index"
						})
					} else {
						uni.switchTab({
							url: "/pages/home/index"
						})
					}
				}
			} else {
				uni.hideLoading()
			}

		})

	}
</script>

<style lang="scss" scoped>
	:deep(.uni-select) {
		border: none !important;
		background-color: none !important;
		height: 91upx
	}

	:deep(.uni-select__selector-item) {
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	.login {
		width: 100vw;
		height: 100vh;
		background-image: url('https://splendid.oss-cn-beijing.aliyuncs.com/static/greenenterprise/login-bgc.png');
		background-size: 100% 100%;
		position: relative;
		padding-top: 530upx;

		.mask {
			background-color: rgba(0, 0, 0, .7);
			width: 100vw;
			height: 100vh;
			position: fixed;
			left: 0;
			top: 0;
			display: flex;
			justify-content: center;
			align-items: center;
			flex-direction: column;
			z-index: 999;

			.wrap {
				width: 587rpx;
				height: 476rpx;
				background: #FFFFFF;
				border-radius: 21rpx;
				padding: 68upx 30upx 0 40upx;
				display: flex;
				flex-direction: column;
				align-items: center;

				.title {

					font-family: Source Han Sans CN;
					font-weight: 500;
					font-size: 33rpx;
					color: #000000;
					align-self: flex-start
				}

				.selection {
					width: 519rpx;
					height: 91rpx;
					background: #FAFAFA;
					border-radius: 14rpx;
					border: 1px solid #BFBFBF;
					margin-top: 30upx;
				}

				button {
					width: 455rpx;
					height: 78rpx;
					background: #0874FA;
					border-radius: 39rpx;
					margin-top: 110upx;
					font-family: Source Han Sans CN;
					font-weight: 400;
					font-size: 34rpx;
					color: #FFFFFF;
					line-height: 78upx;
				}
			}

			image {
				width: 58upx;
				height: 58upx;
				margin-top: 55upx;
			}
		}

		.ph-color {

			font-family: Source Han Sans CN;
			font-weight: 400;
			font-size: 27rpx;
			color: #A4A4A4;
		}

		.image-text {
			position: absolute;
			top: 188upx;
			left: 80upx;
			width: 425upx;
			height: 107upx;
		}

		.huanbao {
			width: 87upx;
			height: 87upx;
			margin-top: 173upx;
		}

		.text {
			margin-top: 23upx;
			font-family: Source Han Serif CN;
			font-weight: 600;
			font-size: 22rpx;
			color: #0250A1;

		}

		.login-enter {
			width: 100%;
			height: 85rpx;
			margin-top: 60upx;
			background: #0874FA;
			border-radius: 42rpx;


			font-family: Source Han Sans CN;
			font-weight: 500;
			font-size: 38rpx;
			color: #FFFFFF;
			line-height: 85rpx;
		}

		.forget-psd {


			font-family: Source Han Sans CN;
			font-weight: 400;
			font-size: 29rpx;
			color: #666666;
			align-self: flex-end;
			margin-top: 35upx;
		}

		.ipt-wrap {
			padding: 0 58upx;
			display: flex;
			flex-direction: column;
			align-items: center;


			.user {
				height: 84rpx;
				background: #F4F6F8;
				border-radius: 42rpx;
				width: 100%;
				display: flex;
				align-items: center;
				padding-left: 35upx;

				.user-icon {
					width: 32upx;
					height: 40upx;
					margin-right: 30upx;
				}

				input {
					flex-grow: 1;
					padding-right: 200upx;
				}
			}

			.pwd {
				height: 84rpx;
				background: #F4F6F8;
				border-radius: 42rpx;
				width: 100%;
				margin-top: 28upx;
				display: flex;
				align-items: center;
				padding-left: 38upx;
				position: relative;

				.psd-icon {
					width: 29upx;
					height: 34upx;
					margin-right: 30upx;
				}

				input {
					flex-grow: 1;
					padding-right: 200upx;
				}

				.eye {
					width: 42upx;
					height: 30upx;
					position: absolute;

					right: 36upx;
					top: 50%;
					transform: translateY(-50%);
				}
			}
		}

	}
</style>